home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / SRS / client / src / stream.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-12  |  18.3 KB  |  786 lines

  1. #include "headers.h" /* has all important stuff */
  2.  
  3. /* this file does the authentication stuff */
  4.  
  5. /* FIX - finish linux mods and the pri stuff for sun */
  6.  
  7. /* initialize stuff.. like SYSLOGFILE */
  8. void initStream()
  9. {
  10.    int fd;
  11.    int res, stop = 0;
  12.  
  13. #  ifdef SUN
  14.    struct stat stats;
  15.    struct strioctl str;
  16. #  endif
  17.    
  18.    struct sockaddr_un sunx;
  19.  
  20.    initSpool();
  21.    memset(sunx.sun_path, 0, sizeof(sunx.sun_path));
  22.  
  23.    debug("(in initStream) initializing server for streaming..\n\n");
  24.  
  25. #  ifdef BSD
  26.    sunx.sun_len = SUN_LEN(&sunx);
  27.    sunx.sun_family = AF_LOCAL;
  28. #  else
  29.    sunx.sun_family = AF_UNIX;
  30. #  endif
  31.  
  32.    (void)strncpy(sunx.sun_path, SYSLOGFILE, sizeof(sunx.sun_path));
  33.    
  34. # if !defined(SUN) && !defined(BSD)
  35. #  ifdef _POSIX_SAVED_IDS
  36.    res = setuid(0);
  37. #  else
  38.    res = seteuid(0);
  39. #  endif
  40.  
  41.    if (res == ERROR) 
  42.    {
  43.       error("error setting [e]uid: %s\n\n", strerror(errno));
  44.       quit(ERROR);
  45.    }
  46. # endif
  47.  
  48. #  ifdef SUN
  49.    res = lstat(SYSLOGFILE, &stats);
  50.    if (res == ERROR)
  51.    {
  52.       error("error with lstat'ing %s: %s\n\n", SYSLOGFILE, strerror(errno));
  53.       quit(ERROR);
  54.    }
  55.  
  56.    if (!S_ISLNK(stats.st_mode))
  57.    {
  58.       error("/dev/log is [possibly] setup wrong.. "
  59.             "linking to %s\n\n", SUNLOGFILE);
  60.  
  61.       (void)unlink(SYSLOGFILE);
  62.  
  63.       res = access(SUNLOGFILE, F_OK);
  64.       if (res == ERROR)
  65.       {
  66.          error("error access'ing %s: %s\n", SUNLOGFILE, strerror(errno));
  67.          quit(ERROR);
  68.       }
  69.  
  70.       res = link(SUNLOGFILE, SYSLOGFILE);
  71.       if (res == ERROR)
  72.       {
  73.          error("error link'ing %s to %s: %s\n", SUNLOGFILE, SYSLOGFILE,
  74.                strerror(errno));
  75.  
  76.          quit(ERROR);
  77.       }
  78.    }
  79.  
  80. #  else
  81.    (void)unlink(SYSLOGFILE);
  82. #  endif
  83.  
  84.    errno = errors = 0;
  85.  
  86. #  ifdef SUN
  87.    fd = open(SYSLOGFILE, O_RDONLY);
  88. #  elif BSD
  89.    fd = socket(AF_LOCAL, SOCK_DGRAM, 0);
  90. #  else
  91.    fd = socket(AF_UNIX, SOCK_STREAM, 0);
  92. #  endif
  93.  
  94.    if ((fd == ERROR) && (errno > 0))
  95.    {
  96. #     ifndef SUN
  97.       error("error with socket(): %s\n\n", strerror(errno));
  98. #     else
  99.       error("error opening %s: %s\n\n", SYSLOGFILE, strerror(errno));
  100.       quit(ERROR);
  101. #     endif
  102.  
  103.       stop = 1;
  104.    }
  105.  
  106. #  ifdef SUN
  107.    str.ic_cmd = I_CONSLOG;
  108.    str.ic_timout = 0;
  109.    str.ic_len = 0;
  110.    str.ic_dp = NULL;
  111.  
  112.    if (ioctl(fd, I_STR, &str) < 0)
  113.    {
  114.       error("error registering to log conmsgs: %s\n\n", strerror(errno));
  115.       quit(ERROR);
  116.    }
  117.  
  118.    /* FIX - open pid file */
  119.    /* do lock here (sun = fnctl with F_SETLK */
  120.  
  121. #  else
  122.    (void)setsockopts(fd, 0);
  123.  
  124.    /* FIX - open pid file */
  125.  
  126. #  ifdef BSD
  127.    /* do lock here (bsd = flock()) */
  128. #  else
  129.    /* in linux it just checks if the file exists.. */
  130. #  endif
  131.  
  132.    if (stop != 1)
  133.    {
  134. #     ifdef BSD
  135.       res = bind(fd, (struct sockaddr *) &sunx, SUN_LEN(&sunx));
  136. #     else
  137.       res = bind(fd, (struct sockaddr *) &sunx, 
  138.                  sizeof(sunx.sun_family) + strlen(sunx.sun_path));
  139. #     endif
  140.  
  141.       if (res == ERROR)
  142.       {
  143.          error("error with bind():\n%s\n\n", strerror(errno));
  144.          stop = 1;
  145.       }
  146.    }
  147. #  endif
  148.  
  149.    if (stop != 1)
  150.    {
  151.       res = chmod(SYSLOGFILE, 0666);
  152.       if (res == ERROR)
  153.       {
  154.          error("error with chmod(): %s\n\n", strerror(errno));
  155.          stop = 1;
  156.       }
  157.  
  158. #    if !defined(SUN) && !defined(BSD)
  159.       if (pwd != NULL)
  160.       {
  161. #        ifdef _POSIX_SAVED_IDS
  162.          res = setuid(pwd->pw_uid);
  163. #        else
  164.          res = seteuid(pwd->pw_uid);
  165. #        endif
  166.  
  167.          if (res == ERROR) 
  168.          {
  169.             error("error setting [e]uid: %s\n\n", strerror(errno));
  170.             quit(ERROR);
  171.          }
  172.       }
  173. #    endif
  174.  
  175. #     ifndef SUN
  176.       res = listen(fd, 5);
  177.       if (res == ERROR)
  178.       {
  179.          error("error with listen(): %s\n\n", strerror(errno));
  180.          stop = 1;
  181.       }
  182. #     endif
  183.    }
  184.  
  185.    if (stop == 1)
  186.    {
  187.       error("error while setting up %s...\n\n", SYSLOGFILE);
  188.       quit(ERROR);
  189.    }
  190.     
  191. # if !defined(SUN) && !defined(BSD)
  192.    if (pwd != NULL)
  193.    {
  194. #     ifdef _POSIX_SAVED_IDS
  195.       res = setuid(pwd->pw_uid);
  196. #     else
  197.       res = seteuid(pwd->pw_uid);
  198. #     endif
  199.  
  200.       if (res == ERROR) 
  201.       {
  202.          error("error setting [e]uid: %s\n\n", strerror(errno));
  203.          quit(ERROR);
  204.       }
  205.    }
  206. # endif
  207.  
  208.    funix = fd;
  209.  
  210.    klogfd = open(KLOGFILE, O_RDONLY);
  211.    if (klogfd == ERROR) 
  212.       error("error opening klogfd.. continuing anyway\n\n");
  213. }
  214.  
  215.  
  216. /* ---------------------- */
  217.  
  218.  
  219. /* read data from SYSLOGFILE.. and send it to server */
  220. void doStreaming()
  221. {
  222.    int res;
  223.    char *res1;
  224.  
  225.    int begin = 0, end = 0;
  226.  
  227. #  if !defined(BSD) && !defined(SUN)
  228.    int fd;
  229. #  endif
  230.  
  231. #  ifndef SUN
  232.    int count = 0;
  233. #  endif
  234.  
  235.    int nospool = ERROR;
  236.  
  237.    struct timeval tm;
  238.    struct tm *tv;
  239.    time_t value;
  240.    
  241. #  ifndef SUN
  242.    char newmsg[MAXLOGSIZE];
  243.    char logmsg[MAXLOGSIZE];
  244. #  endif
  245.  
  246.    char readbuf[MAXREADSIZE];
  247.    char spoolfile[MAXFNAMESIZE];  
  248.  
  249.    char newbuf[MAXLOGSIZE];
  250.    char testbuf[MAXLOGSIZE];
  251.  
  252. #  ifndef SUN
  253.    char *logptr, *dataptr, *newptr;
  254. #  endif
  255.  
  256. #  ifdef BSD
  257.    u_char cmsg[MAXREADSIZE/4];
  258.  
  259.    struct iovec iov;
  260.    struct msghdr msghdr;
  261.  
  262. #  elif SUN
  263.    char *bufptr;
  264.    int flags = 0;
  265. #  endif
  266.  
  267.    errno = 0;
  268.    FD_ZERO(&readfds);
  269.  
  270.    memset(spoolfile, 0, sizeof(spoolfile));
  271.  
  272.    if (spoolFile == NULL)
  273.       (void)sprintf(spoolfile, "%s/spool/%s", SRSdir, LOGFILE);
  274.  
  275.    else (void)snprintf(spoolfile, sizeof(spoolFile)-1, "%s", spoolFile);
  276.  
  277.    if (spoolfd != NULL) (void)fclose(spoolfd);
  278.  
  279. # if !defined(SUN) && !defined(BSD)
  280. #  ifdef _POSIX_SAVED_IDS
  281.    res = setuid(0);
  282. #  else
  283.    res = seteuid(0);
  284. #  endif
  285.  
  286.    if (res == ERROR) 
  287.    {
  288.       error("error setting [e]uid: %s\n\n", strerror(errno));
  289.       quit(ERROR);
  290.    }
  291. # endif
  292.  
  293.    if (nospool != 1)
  294.    {
  295.       spoolfd = fopen(spoolfile, "rb");
  296.       if (spoolfd == NULL)
  297.       {
  298.          error("(in doStreaming) error opening: %s: %s\n\n", spoolfile, 
  299.                strerror(errno));
  300.  
  301.          nospool = 1;
  302.       }
  303.    }
  304.  
  305. # if !defined(SUN) && !defined(BSD)
  306. #  ifdef _POSIX_SAVED_IDS
  307.    res = setuid(pwd->pw_uid);
  308. #  else
  309.    res = seteuid(pwd->pw_uid);
  310. #  endif
  311.  
  312.    if (res == ERROR) 
  313.    {
  314.       error("error setting [e]uid: %s\n\n", strerror(errno));
  315.       quit(ERROR);
  316.    }
  317. # endif
  318.  
  319.    sendSysConf();
  320.  
  321. #  ifdef NOSSL
  322.    startPings(); /* using this will SSL breaks stuff */
  323. #  endif
  324.  
  325.    debug("now telling server we're streaming..\n");
  326.    streaming = 1, send_data("START STREAM\n");
  327.  
  328.    /* ----------------- */
  329.  
  330.    if (nospool != 1)
  331.    {
  332.       debug("now checking for spooled data...\n");
  333.  
  334.       while(1)
  335.       {
  336.          errno = 0;
  337.          memset(readbuf, 0, sizeof(readbuf));
  338.  
  339.          res1 = fgets(readbuf, sizeof(readbuf)-1, spoolfd);
  340.  
  341.          if ((res1 == NULL) && (errno == EINTR)) continue;
  342.          else if (res1 != NULL)
  343.          {
  344.             if (strncmp(readbuf, "STREAM", 6) == 0)
  345.             {
  346.                /* there is data in the spool file.. so we were spooling */
  347.  
  348.                if (didspool != 1)
  349.                {
  350.                   debug("possible spooled data...\n");
  351.                   debug("streaming this (if any) before real-time data\n\n");
  352.  
  353.                   didspool = 1;
  354.                }
  355.  
  356.                if (((readbuf[0] != '\0') && (readbuf[0] != '\n')) &&
  357.                    (isprint((int)readbuf[1]) != 0)) send_data(readbuf);
  358.             }
  359.          }
  360.  
  361.          else break;
  362.       }
  363.  
  364.       spooling = didspool = 0;
  365.  
  366.       debug("spooled data (if any) was sent...\n");
  367.       debug("now streaming live logs\n\n");
  368.    }
  369.  
  370.    else nospool = 0;
  371.  
  372. # if !defined(SUN) && !defined(BSD)
  373. #  ifdef _POSIX_SAVED_IDS
  374.    res = setuid(0);
  375. #  else
  376.    res = seteuid(0);
  377. #  endif
  378.  
  379.    if (res == ERROR) 
  380.    {
  381.       error("error setting [e]uid: %s\n\n", strerror(errno));
  382.       quit(ERROR);
  383.    }
  384. # endif
  385.  
  386.    if (spoolfd != NULL) (void)fclose(spoolfd);
  387.    (void)unlink(spoolfile);
  388.  
  389. # if !defined(SUN) && !defined(BSD)
  390. #  ifdef _POSIX_SAVED_IDS
  391.    res = setuid(pwd->pw_uid);
  392. #  else
  393.    res = seteuid(pwd->pw_uid);
  394. #  endif
  395.  
  396.    if (res == ERROR) 
  397.    {
  398.       error("error setting [e]uid: %s\n\n", strerror(errno));
  399.       quit(ERROR);
  400.    }
  401. # endif
  402.  
  403.    /* ---------------------------------------------------------------- */
  404.  
  405.    debug("sending \"BEGIN LOGS\" marker...\n");
  406.  
  407.    value = time ((time_t *)NULL);
  408.    tv = localtime (&value);
  409.  
  410.    sprintf(testbuf, "STREAM : ! --- BEGIN LOGS FOR CLIENT ID %s at "
  411.            "%d:%d:%d (%d.%d.%d) ---\n", ID, tv->tm_hour, tv->tm_min,
  412.            tv->tm_sec, (tv->tm_mon + 1), tv->tm_mday, tv->tm_year);
  413.  
  414.    send_data (testbuf);
  415.  
  416.    debug("now waiting for system logs to stream...\n\n");
  417.  
  418. #  ifdef BSD
  419.    iov.iov_base = readbuf;
  420.    iov.iov_len = sizeof(readbuf)-1;
  421. #  endif
  422.  
  423.    while(1)
  424.    {
  425. #     ifdef SUN
  426.       struct log_ctl hdr;
  427.       struct strbuf ctl, dat;
  428. #     endif
  429.  
  430.       memset(readbuf, 0, sizeof(readbuf));
  431.  
  432.       FD_SET(funix, &readfds);
  433.       FD_SET(sockfd, &readfds);
  434.       if (klogfd > 0) FD_SET(klogfd, &readfds);
  435.  
  436. #     if !defined(SUN) && !defined(BSD)
  437.       for (nfds = 0; nfds < FD_SETSIZE-2; nfds++)
  438.          if (FD_ISSET(nfds, &unixm)) FD_SET(nfds, &readfds);
  439. #     endif
  440.  
  441.       tm.tv_sec = MAXTIMEOUT * 2, tm.tv_usec = 0;
  442.  
  443.       nfds = 0, errno = 0;
  444.       nfds = select(FD_SETSIZE, (fd_set *) &readfds, (fd_set *) NULL,
  445.                    (fd_set *) NULL, &tm);
  446.                 
  447.       /* won't happen.. we don't have a timeout */
  448.       if (nfds == 0)
  449.       {
  450.          debug("no select activity... restarting in loop\n");
  451.          debug("sending a ping (to check for sigpipe) to server..\n");
  452.  
  453.          FD_CLR(funix, &readfds);
  454.          FD_CLR(sockfd, &readfds);
  455.          if (klogfd > 0) FD_CLR(klogfd, &readfds);
  456.  
  457.          send_data("PING CHECK\n");
  458.          continue;
  459.       }
  460.     
  461.       else if (nfds == ERROR)
  462.       {
  463.          if (errno == EINTR) continue;
  464.  
  465.          error("error with select(): %s\n\n", strerror(errno));
  466.          quit(ERROR);
  467.       }
  468.  
  469.       /* ------------------------------------- */
  470.     
  471.       /* handle data from the server */
  472.       if (FD_ISSET(sockfd, &readfds)) 
  473.       {
  474.          debug("new data from server\n");
  475.  
  476.          memset(readbuf, 0, sizeof(readbuf));
  477.          recv_data(readbuf, sizeof(readbuf));
  478.  
  479.          FD_CLR(sockfd, &readfds);
  480.       }
  481.  
  482.       /* handle new data on /dev/klog */
  483.       if ((klogfd > 0) && (FD_ISSET(klogfd, &readfds)))
  484.       {
  485.          memset(readbuf, 0, sizeof(readbuf));
  486.  
  487.          res = read(klogfd, readbuf, sizeof(readbuf)-1);
  488.          if (res == ERROR)
  489.          {
  490.             error("error reading klogfd.. removing\n\n");
  491.  
  492.             FD_CLR(klogfd, &readfds);
  493.             (void)close(klogfd), klogfd = ERROR;
  494.  
  495.             continue;
  496.          }
  497.  
  498.          else if (((readbuf[0] != '\0') && (readbuf[0] != '\n')) &&
  499.                   (isprint((int)readbuf[1]) != 0))
  500.          {
  501.             /* FIX - do it (add the kern def pri.. "kernel: " and */
  502.             /*     - doLogging it.. then sending it to server     */
  503.  
  504.             debug("new klog msg = %s\n", readbuf);
  505.          }
  506.  
  507.          FD_CLR(klogfd, &readfds);
  508.       }
  509.  
  510. #     if !defined(SUN) && !defined(BSD)
  511.       for (fd = 0; fd < FD_SETSIZE; fd++)
  512.          if ((FD_ISSET(fd, &readfds)) && (FD_ISSET(fd, &unixm)))
  513.  
  514. #     else
  515.       if (FD_ISSET(funix, &readfds)) 
  516. #     endif
  517.  
  518.       {
  519.          memset(readbuf, 0, sizeof(readbuf));
  520.  
  521. #        ifdef BSD
  522.          memset(cmsg, 0, sizeof(cmsg));
  523.          memset(&msghdr, 0, sizeof(msghdr));
  524.  
  525.          msghdr.msg_iov = &iov;
  526.          msghdr.msg_iovlen = 1;
  527.          msghdr.msg_flags = 0;
  528.          msghdr.msg_control = (caddr_t)cmsg;
  529.          msghdr.msg_controllen = sizeof(cmsg);
  530.  
  531.          /* FIX - do something with credentials.. */
  532.  
  533.          res = recvmsg(funix, &msghdr, 0);
  534.          if (res == ERROR)
  535.          {
  536.             error("error with recvmsg from %s: %s\n\n", SYSLOGFILE,
  537.                   strerror(errno));
  538.  
  539.             quit(ERROR);
  540.          }
  541.  
  542. #        elif SUN
  543.          dat.buf = readbuf;
  544.          dat.maxlen = sizeof(readbuf) - 1;
  545.  
  546.          ctl.buf = (caddr_t)&hdr;
  547.          ctl.maxlen = sizeof(struct log_ctl);
  548.  
  549.          while(1)
  550.          {
  551.             errno = 0;
  552.  
  553.             res = getmsg(funix, &ctl, &dat, &flags);
  554.             if (res != MOREDATA)
  555.                if ((res != ERROR) || ((res == ERROR) && (errno != EINTR)))
  556.                   break;
  557.  
  558.             bufptr = &dat.buf[dat.len], *bufptr = '\0';
  559.             while ((*bufptr != '\n') && (bufptr != readbuf)) bufptr -= 1;
  560.  
  561.             if (bufptr != readbuf) *bufptr = '\0';
  562.  
  563.             if (((readbuf[0] != '\0') && (readbuf[0] != '\n')) &&
  564.                 (isprint((int)readbuf[1]) != 0))
  565.             {
  566.                send_data("STREAM : %s%c", readbuf,
  567.                          (readbuf[strlen(readbuf)-1] != '\n' ? '\n' : '\0'));
  568.  
  569.                doLogging(readbuf);
  570.             }
  571.  
  572.             if (readbuf != bufptr) 
  573.             {
  574.                strcpy(readbuf, bufptr); 
  575.                dat.maxlen = sizeof(readbuf) - strlen(readbuf) - 1;
  576.                dat.buf = &readbuf[strlen(readbuf)];
  577.             }
  578.  
  579.             else
  580.             {
  581.                dat.maxlen = sizeof(readbuf) - 1;
  582.                dat.buf = readbuf;
  583.             }
  584.          }
  585.  
  586.          if ((res == 0) && (dat.len > 0))
  587.          {
  588.             dat.buf[dat.len] = '\0';
  589.  
  590.             if (((readbuf[0] != '\0') && (readbuf[0] != '\n')) &&
  591.                 (isprint((int)readbuf[1]) != 0))
  592.             {
  593.                send_data("STREAM : %s%c", readbuf,
  594.                          (readbuf[strlen(readbuf)-1] != '\n' ? '\n' : '\0'));
  595.  
  596.               doLogging(readbuf);
  597.             }
  598.          }
  599.  
  600.          else if ((res == ERROR) && (errno != EINTR))
  601.          {
  602.             error("error in getmsg: %s\n\n", strerror(errno));
  603.  
  604.             (void)close(funix);
  605.             funix = ERROR;
  606.  
  607.             quit(ERROR);
  608.          }
  609.  
  610. #        else
  611.          while(1)
  612.          {
  613.             errno = 0;
  614.  
  615.             memset(readbuf, 0, sizeof(readbuf));
  616.             res = read(fd, readbuf, sizeof(readbuf)-1);
  617.  
  618.             if ((res <= 0) && (errno > 0))
  619.             {
  620.                if (errno == EINTR) continue;
  621.  
  622.                error("error with read(): %s\n", strerror(errno));
  623.                (void)close(fd), quit(ERROR);
  624.             }
  625.  
  626.            else break;
  627.          }
  628.  
  629.          FD_CLR(fd, &readfds);
  630.          FD_CLR(fd, &unixm);
  631. #        endif
  632.  
  633. #        ifndef SUN
  634.          if (((readbuf[0] != '\0') && (readbuf[0] != '\n')) &&
  635.              (isprint((int)readbuf[1]) != 0))
  636.          {
  637.             memset(newmsg, 0, sizeof(newmsg));
  638.             memset(logmsg, 0, sizeof(logmsg));
  639.  
  640.             send_data("STREAM : %s%c", readbuf,
  641.                       (readbuf[strlen(readbuf)-1] != '\n' ? '\n' : '\0'));
  642.  
  643.             doLogging(readbuf);
  644.  
  645.             logptr = logmsg;
  646.             dataptr = readbuf, dataptr += 20; 
  647.  
  648.             count = 0;
  649.             while ((*dataptr) && (isprint((int)*dataptr) != 0) &&
  650.                    (count < (int)sizeof(logmsg)))
  651.             {
  652.                *logptr++ = *dataptr++;
  653.                count++;
  654.             }
  655.  
  656.             if (isprint((int)prevlogmsg[0]) == 0) 
  657.             {
  658.                (void)strncpy(prevlogmsg, logmsg, sizeof(prevlogmsg)-1);
  659.                prevlogtime = time(NULL);
  660.  
  661.                doLogging(readbuf);
  662.             }
  663.  
  664.             else if (strncmp(logmsg, prevlogmsg, strlen(prevlogmsg)) == 0)
  665.             {
  666.                if ((time(NULL) - prevlogtime) >= REPTIME)
  667.                {
  668.                   char repmsg[MAXLOGSIZE - 20];
  669.  
  670.                   memset(repmsg, 0, sizeof(repmsg));
  671.  
  672.                   if (repcount == 1)
  673.                      sprintf(repmsg, " last message repeated %d time\n",
  674.                              repcount);
  675.  
  676.                   else
  677.                      sprintf(repmsg, " last message repeated %d times\n",
  678.                              repcount);
  679.  
  680.                   repcount = 0;
  681.                   prevlogtime = time(NULL);
  682.  
  683.                   count = 0;
  684.                   newptr = newmsg, dataptr = readbuf;
  685.  
  686.                   while ((*dataptr) && (isprint((int)*dataptr) != 0) &&
  687.                          (count < (int)sizeof(newmsg)) && (count < 19))
  688.                   {
  689.                      *newptr++ = *dataptr++;
  690.                      count++;
  691.                   }
  692.  
  693.                   strncat(newmsg, repmsg, 
  694.                           sizeof(newmsg) - strlen(newmsg) - 1);
  695.  
  696.                   debug("newmsg = %s\n", newmsg);
  697.                   doLogging(newmsg);
  698.                }
  699.  
  700.                else
  701.                {
  702.                   repcount++;
  703.                   debug("last message repeated...\n\n");
  704.                }
  705.             }
  706.  
  707.             else
  708.             {
  709.                prevlogtime = time(NULL);
  710.                (void)strncpy(prevlogmsg, logmsg, sizeof(prevlogmsg)-1);
  711.                doLogging(readbuf);
  712.             }
  713.          }
  714. #        endif
  715.       }
  716.  
  717.       value = time(NULL);
  718.       tv = localtime (&value);
  719.  
  720.       if (begin == 1 && tv->tm_hour != BEGIN_HOUR)
  721.       {
  722.         debug ("-- RESET BEGIN MARKER --\n");
  723.         begin = 0;
  724.       }
  725.  
  726.       if (end == 1 && tv->tm_hour != END_HOUR)
  727.       {
  728.         debug ("-- RESET END MARKER --\n");
  729.         end = 0;
  730.       }
  731.  
  732.       if (tv->tm_hour == BEGIN_HOUR && begin != 1)
  733.       {
  734.          begin = 1;
  735.          memset(newbuf, 0, sizeof(newbuf));
  736.  
  737.          sprintf(newbuf, "STREAM : ! --- BEGIN LOGS FOR CLIENT ID %s "
  738.                  "at %d:%d:%d (%d.%d.%d) ---\n", ID, tv->tm_hour, tv->tm_min,
  739.                  tv->tm_sec, (tv->tm_mon + 1), tv->tm_mday, tv->tm_year);
  740.  
  741.          send_data(newbuf);
  742.  
  743.          debug("--- BEGIN LOGS FOR CLIENT ID %s "
  744.                "at %d:%d:%d (%d.%d.%d) ---\n", ID, tv->tm_hour, tv->tm_min,
  745.                tv->tm_sec, (tv->tm_mon + 1), tv->tm_mday, tv->tm_year);
  746.       }
  747.  
  748.       if (tv->tm_hour == END_HOUR && tv->tm_min == END_MINUTE &&
  749.           tv->tm_sec >= END_SECOND && end != 1)
  750.       {
  751.          end = 1;
  752.          memset(newbuf, 0, sizeof(newbuf));
  753.  
  754.          sprintf(newbuf, "STREAM : ! --- END LOGS FOR CLIENT ID %s "
  755.                  "at %d:%d:%d (%d.%d.%d) ---\n", ID, tv->tm_hour,
  756.                  tv->tm_min, tv->tm_sec, (tv->tm_mon + 1), tv->tm_mday,
  757.                  tv->tm_year);
  758.  
  759.          send_data(newbuf);
  760.  
  761.          debug("--- END LOGS FOR CLIENT ID %s "
  762.                "at %d:%d:%d (%d.%d.%d) ---\n", ID, tv->tm_hour,
  763.                tv->tm_min, tv->tm_sec, (tv->tm_mon + 1), tv->tm_mday,
  764.                tv->tm_year);
  765.       }
  766.  
  767. #     if !defined(SUN) && !defined(BSD)
  768.       if (FD_ISSET(funix, &readfds))
  769.       {
  770.          /* accept a new connection */
  771.          /* debug("got new unix connect\n"); */
  772.  
  773.          fd = accept(funix, (struct sockaddr *)NULL, 0);
  774.          if (fd >= 0)
  775.          {
  776.             FD_SET(fd, &unixm);
  777.             FD_SET(fd, &readfds);
  778.          }
  779.  
  780.          else error("error with accept(): %s\n", strerror(errno));
  781.       }
  782. #     endif
  783.  
  784.    }
  785. }
  786.